/**
 * Created by Administrator on 2017/10/30.
 */
$(function () {
    var res_id = $('#res_id').val();
    var height = $(window).outerHeight(true);
    $('body .wraper').css('minHeight', height);
    var avg = [];
    var num = [];
    var money = [];
    var month = [];
    var monthData1 = [{
        name: '营业额',
        data: money
    }];
    var monthData2 = [{
        name: '单数',
        data: num
    }, {
        name: '单均消费',
        data: avg
    }];
    $.ajax({
        url: '/restaurant/zduMobile/daystatic/res_id/'+res_id,
        type: 'POST',
        data: {},
        dataType: 'JSON',
        beforeSend: function () {
            $('.dataload').show();
        },
        success: function (data) {
            $('.dataload').hide();
            if (data.status == 'S') {
                $('.yesterday').html(data.data.yesterdayData.time);
                $('.num').html(data.data.yesterdayData.num);
                $('.money').html(data.data.yesterdayData.money);
                $.each(data.data.list.day, function (i, k) {
                    month.push(k.toString());
                });

                $.each(data.data.list.money, function (i, k) {
                    money.push(parseFloat(k));
                });

                $.each(data.data.list.avg, function (i, k) {
                    avg.push(parseFloat(k));
                });

                $.each(data.data.list.num, function (i, k) {
                    num.push(parseFloat(k));
                });
            } else if (data.status == 'F') {
                window.location.href = data.url;
            }
            setCharts('#container1', '', '', month, monthData1);
            setCharts('#container2', 'column', 'true', month, monthData2);
        }
    });

    function setCharts(chartname, type, status, month, monthData) {
        $(chartname).highcharts({
            chart: {
                type: type
            },
            title: {
                text: ''
            },
            subtitle: {
                text: ''
            },
            colors: [
                '#00a5f3',
                '#febd3e'
            ],
            xAxis: {
                type: 'category',
                categories: month,
                tickWidth: 0 // 主刻度的宽度

            },
            yAxis: {
                title: {
                    text: ''
                },
                labels: {
                    formatter: function () {
                        var value = this.value;
                        if (value >= 10000) {
                            return value / 10000 + '万';
                        } else {
                            return value;
                        }
                    }
                }
            },
            credits: {
                enabled: false
            },
            legend: {
                verticalAlign: 'top',
                enabled: status
            },
            exporting: {
                enabled: false
            },
            series: monthData
        });
    }
});
